package com.jy.horny.function.login

import com.framework.network.remote.NetworkObserver
import com.framework.network.remote.endRequest
import com.framework.network.remote.error
import com.framework.network.remote.requestObserver
import com.framework.network.remote.startRequest
import com.framework.network.remote.success
import com.jy.horny.base.BaseVMViewModel
import com.jy.horny.base.HttpRequestListener
import com.jy.horny.base.Request
import com.jy.horny.model.LoginUserModel

/**
 * 登录页面
 */
class LoginViewModel : BaseVMViewModel(){

    fun getLogin(listener: HttpRequestListener<LoginUserModel>){
        request(listener,request=object :Request{
            override fun request(map: HashMap<String, Any>, requestEndListener: (() -> Unit?)?) {
                apiService?.postAuthLogin(map)?.requestObserver(
                    NetworkObserver<LoginUserModel>().startRequest {
                        listener.startRequest(it)
                    }.success {
                        listener.success(it)
                    }.error {
                        listener.error(it)
                    }.endRequest {
                        listener.endRequest()
                        requestEndListener?.invoke()
                    })

            }

        })
    }

}